<html>
<head><meta charset="utf-8"><title>How to add a timeout? · t-cargo/PubGrub · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/260232-t-cargo/PubGrub/index.html">t-cargo/PubGrub</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/260232-t-cargo/PubGrub/topic/How.20to.20add.20a.20timeout.3F.html">How to add a timeout?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212871944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260232-t-cargo/PubGrub/topic/How%20to%20add%20a%20timeout%3F/near/212871944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/260232-t-cargo/PubGrub/topic/How.20to.20add.20a.20timeout.3F.html#212871944">(Oct 09 2020 at 20:27)</a>:</h4>
<p>Dependency resolution is NP-Hard. So if we fuzz enough we will find cases that take a long time. If we find one it is interesting to look at it and figure out how it escaped our optimizations. In Cargo when there are debug assertions we have a hard cutoff, a time out where test fail. <a href="https://github.com/rust-lang/cargo/issues/6258">https://github.com/rust-lang/cargo/issues/6258</a> is the issue track the propcases found this way.</p>
<p>A users of our crate may want to have a time out. For example a website that lets you see all the transitive deps of a cargo.toml, is opening itself up to a denial of services if there is an input that takes a while. </p>
<p>So for testing I want to add a way to have a timeout, but it may as well be an unobtrusive part of the api, suggestions?</p>



<a name="212874718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260232-t-cargo/PubGrub/topic/How%20to%20add%20a%20timeout%3F/near/212874718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/260232-t-cargo/PubGrub/topic/How.20to.20add.20a.20timeout.3F.html#212874718">(Oct 09 2020 at 20:56)</a>:</h4>
<p>My thought is made <code>DependencyProvider</code> has an optional method <code>fn callback(&amp;self) -&gt; Result&lt;(), Erorr&gt; {Ok(())}</code> that we call as part of the main loop. If it is overwritten and returns an <code>Err</code> then resolution will fail with that <code>Err</code>. That lets our tests (or a website) add a timeout, and a CLI add an interrupt. But I am open to other suggestions.</p>



<a name="212877253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260232-t-cargo/PubGrub/topic/How%20to%20add%20a%20timeout%3F/near/212877253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthieu Pizenberg <a href="https://rust-lang.github.io/zulip_archive/stream/260232-t-cargo/PubGrub/topic/How.20to.20add.20a.20timeout.3F.html#212877253">(Oct 09 2020 at 21:22)</a>:</h4>
<p>Having a dedicated <code>callback</code> seems like a good idea</p>



<a name="212890454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260232-t-cargo/PubGrub/topic/How%20to%20add%20a%20timeout%3F/near/212890454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthieu Pizenberg <a href="https://rust-lang.github.io/zulip_archive/stream/260232-t-cargo/PubGrub/topic/How.20to.20add.20a.20timeout.3F.html#212890454">(Oct 10 2020 at 00:25)</a>:</h4>
<p>I just realize I forgot the rest of what I wanted to say above. I added "dedicated" not in opposition to optional, optional is a good idea, but in opposition to hijacking <code>list_available_versions</code> and <code>get_dependencies</code> which can also return errors.</p>



<a name="212945618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260232-t-cargo/PubGrub/topic/How%20to%20add%20a%20timeout%3F/near/212945618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/260232-t-cargo/PubGrub/topic/How.20to.20add.20a.20timeout.3F.html#212945618">(Oct 11 2020 at 02:59)</a>:</h4>
<p>I'm wondering if callback should take an argument of a struct that has some stats of how much work the resolver has done. For now it can provide no info, but then we can add stuff in the future without breaking the api.</p>



<a name="213300285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260232-t-cargo/PubGrub/topic/How%20to%20add%20a%20timeout%3F/near/213300285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Tokarev <a href="https://rust-lang.github.io/zulip_archive/stream/260232-t-cargo/PubGrub/topic/How.20to.20add.20a.20timeout.3F.html#213300285">(Oct 14 2020 at 14:51)</a>:</h4>
<p>Let's bikeshed the naming I guess. Current suggestions:</p>
<ul>
<li>checkpoint</li>
<li>loop_checkpoint</li>
<li>check_interrupt</li>
<li>check_interruption</li>
<li>cancellation</li>
<li>should_cancel</li>
<li>should_interrupt</li>
</ul>



<a name="213300482"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260232-t-cargo/PubGrub/topic/How%20to%20add%20a%20timeout%3F/near/213300482" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Tokarev <a href="https://rust-lang.github.io/zulip_archive/stream/260232-t-cargo/PubGrub/topic/How.20to.20add.20a.20timeout.3F.html#213300482">(Oct 14 2020 at 14:52)</a>:</h4>
<p>I think something like <code>should_cancel</code>/<code>should_interrupt</code> reads well with error handling question mark that follows <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="213300629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260232-t-cargo/PubGrub/topic/How%20to%20add%20a%20timeout%3F/near/213300629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/260232-t-cargo/PubGrub/topic/How.20to.20add.20a.20timeout.3F.html#213300629">(Oct 14 2020 at 14:53)</a>:</h4>
<p>I'm feeling should_cancel at the moment.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>